import 'package:fluro/fluro.dart';
import 'package:flutter/material.dart';
import 'package:riverpod_t/routers/routers.dart';

class NavigatorUtils {
  NavigatorUtils._();

  static Future push(BuildContext context, String path,
      {bool replace = false,
      bool clearStack = false,
      TransitionType? transition,
      Duration? transitionDuration,
      bool? opaque,
      Object? arguments}) async {
    if (!context.mounted) {
      return Future.value();
    }

    return NovelRoutes.fluroRouter.navigateTo(
      opaque: opaque,
      context,
      path,
      replace: replace,
      clearStack: clearStack,
      transition: transition ?? TransitionType.cupertino,
      transitionDuration: transitionDuration,
      routeSettings: RouteSettings(arguments: arguments),
    );
  }

  /// 返回
  static void pop(BuildContext context, {Object? result}) {
    Navigator.pop(context, result);
  }

  /// 返回到指定页面
  static void popUntil(BuildContext context, String path) {
    if (path.isEmpty) return;
    Navigator.popUntil(context, ModalRoute.withName(path));
  }

  static bool canPop(BuildContext context) {
    return Navigator.canPop(context);
  }

  ///收起软键盘
  static void unFocus() {
    FocusManager.instance.primaryFocus?.unfocus();
  }
}
